package com.theshy.test.domain;

import com.theshy.test.dao.Student;
import com.theshy.test.dao.Teacher;

public class TeacherDao {

    static Teacher[] teachers = new Teacher[3];

    static {
        Teacher s1 = new Teacher(204911,"wbk",20,"2000");
        Teacher s2 = new Teacher(204912,"zmh",20,"2000");
        teachers[0]=s1;
        teachers[1]=s2;
    }
    public boolean isExist(int id) {

        int index = getIndex(id);
        if(index==-1){
            return false;
        }else{
            return true;
        }

    }


    public int getIndex(int id){
        int index =-1;
        for (int i = 0; i < teachers.length; i++) {
            if(teachers[i]!=null&&teachers[i].getId()==id){
                index=i;
                break;
            }
        }
        return index;
    }

    public boolean AddTeacher(Teacher t) {
        int index = -1;

        for (int i = 0; i < teachers.length; i++) {
            if(teachers[i]==null){
                index = i;
                break;
            }
        }

        if(index==-1){
            return false;
        }else{
            teachers[index]=t;
            return true;
        }
    }

    public Teacher[] checkTeacher() {


        return teachers;
    }

    public void DeleteTeacher(int id) {

        int a = getIndex(id);
        teachers[a]=null;
    }

    public void changeTeacher(Teacher teacher) {

        int id = getIndex(teacher.getId());
        teachers[id]=teacher;

    }
}
